﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "logger.h"
#include "formlog.h"
#include "formmodbus.h"
#include "tcprequester.h"
#include "serialportrequester.h"
#include "modbustcp.h"
#include "modbusrtu.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    qInstallMessageHandler(Logger::CustomMessageHandler);

    intModbusTcp();
    intModbusRtu();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::intModbusTcp()
{
    ModbusTcp *req=new ModbusTcp(this);
    req->setName("modbus_tcp");
    FormModbus *w=new FormModbus(this);
    w->setComm(req);
    ui->tabWidget->addTab(w,"modbus_tcp");
}

void MainWindow::intModbusRtu()
{
    BaseModbus *req=new ModbusRtu(this);
    req->setName("modbus_rtu");
    FormModbus *w=new FormModbus(this);
    w->setComm(req);
    ui->tabWidget->addTab(w,"modbus_tcp");
}

void MainWindow::on_actionLog_triggered()
{
    static FormLog frm;
    frm.show();
}
